/*
 * > /*
>  * INSANE - Interactive Structural Analysis Environment
>  *
>  * Copyright (C) 2003-2004
>  * Universidade Federal de Minas Gerais
>  * Escola de Engenharia
>  * Departamento de Engenharia de Estruturas
>  *
>  * Author's email :     insane@dees.ufmg.br
>  * Author's Website :   http://www.dees.ufmg.br/insane
>  *
>  * This program is free software; you can redistribute it and/or
>  * modify it under the terms of the GNU General Public License
>  * as published by the Free Software Foundation; either version 2
>  * of the License, or any later version.
>  *
>  * This program is distributed in the hope that it will be useful,
>  * but WITHOUT ANY WARRANTY; without even the implied warranty of
>  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
>  * GNU General Public License for more details.
>  *
>  * You should have received a copy of the GNU General Public License
>  * along with this program; if not, write to the Free Software
>  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-
> 1307, USA.
 *
 */

package br.ufmg.dees.insane.draw;

import java.awt.Dimension;
import java.awt.Font;
import java.awt.FontMetrics;
import java.awt.Graphics2D;
import java.awt.Point;
import java.awt.Rectangle;
import java.awt.geom.AffineTransform;
import java.util.Vector;

/**
 * @author Fonseca, Flavio & Pitangueira, Roque
 * @since	May 2004
 */
public class StringDraw extends Draw {
	
    public static final String[] fonts = {"Arial","Monospaced","SansSerif","Time"};
	
	private String str;
	private Point centre;
	private String fontType = fonts[0];
	private int fontSize = 10;
	private byte fontStyle = Font.PLAIN;
	
//*****************************************************************************
	
    public void setCentre(Point a) {
		centre = a;
	}
	
//*****************************************************************************
	
	public Point getCentre() {
		return centre;
	}
	
//*****************************************************************************
	
	public void setString(String a) {
		str = a;
	}
	
//*****************************************************************************
	
	public String getString() {
		return str;
	}
	
//*****************************************************************************
	
	public StringDraw() {
		this(new Point());
	}
	
//*****************************************************************************
	
	public StringDraw(Point loc) {
		this(loc, 0);
	}
	
//*****************************************************************************
	
	public StringDraw(Point loc, double theta) {
		this(loc, theta, null);
	}
	
//*****************************************************************************
	
	public StringDraw(Point loc, double theta, Object represents) {
		this.setLocation(loc);
		this.setAngle(theta);
		this.setRepresents(represents);
		this.setSize(new Dimension(4, 32));
	}
	
//*****************************************************************************
	
    public Vector<Object> getShapes() {
        return null;
    }
	
//*****************************************************************************
	
    /**
     * Draws in a given Graphics.
     *
     * @see   java.awt.Graphics
     */
	public void draw(Graphics2D g2) {
		
		int x = this.getLocation().x;
		int y = this.getLocation().y;
		
		if(this.fontStyle==0){
			g2.setFont(new Font(this.fontType, Font.PLAIN, this.fontSize));
		}
		if(this.fontStyle==1){
			g2.setFont(new Font(this.fontType, Font.BOLD, this.fontSize));
		}
		if(this.fontStyle==2){
			g2.setFont(new Font(this.fontType, Font.ITALIC, this.fontSize));
		}
		if(this.fontStyle==3){
			g2.setFont(new Font(this.fontType,Font.BOLD+Font.ITALIC, this.fontSize));
		}
		
		
		FontMetrics metrics = g2.getFontMetrics();
		int txtWidth = metrics.stringWidth(str);
		int centreX = x - txtWidth / 2;
		
		AffineTransform saved = g2.getTransform();
		AffineTransform rotate = AffineTransform.getRotateInstance(this.getAngle()*-1, centre.getX(), centre.getY());
		g2.transform(rotate);
		g2.drawString(str, centreX, y);
		g2.setTransform(saved);
		
	}
	
//*****************************************************************************
	
    /**
     * Returns the draw bounds in device units.
     *
     * @return the draw bounds
     */
    public Rectangle getBounds() {
		
		int x = this.getLocation().x;
		int y = this.getLocation().y;
		int W = this.getSize().width * 4;
		int H = this.getSize().height * 4;
		
		return new Rectangle((int)(x - W/2), (int)(y - H/2), W, H);
	}
	
    public void setFont(String ftype, int fsize, byte fstyle) {
        this.fontType = ftype;
        this.fontSize = fsize;
        this.fontStyle= fstyle;
       }
    
    public void setFontType(String f) {
     this.fontType = f;
    }
    
    public void setFontSize(int fs) {
        this.fontSize = fs;
    }
    
    public void setFontStyle(byte fs) {
        this.fontStyle = fs;
    }
//*****************************************************************************
}
